package com.ys.web.background.service.impl;

import com.ys.utils.base.j2se.StringHandler;
import com.ys.utils.spring.config.SystemError;
import com.ys.web.background.mapper.BackgroundComplainMapper;
import com.ys.web.background.service.BackgroundComplainService;
import com.ys.web.background.service.BackgroundGroupService;
import com.ys.web.background.service.BackgroundUserService;
import com.ys.web.background.vo.BackgroundComplainListVo;
import com.ys.web.background.vo.ComplainListVo;
import com.ys.web.user.complain.mapper.ComplainMapper;
import com.ys.web.user.complain.po.ComplainPO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @ 名称:
 * @ 创建人: dhf
 * @ 参数： null
 * @ 创建时间: 2022/5/10
 * @ 修改人和其它信息
 * @ 返回值:
 */
@Slf4j
@Service
public class BackgroundComplainServiceImpl implements BackgroundComplainService {

    @Autowired
    private BackgroundComplainMapper backgroundComplainMapper;

    @Autowired
    private ComplainMapper complainMapper;

    @Autowired
    private BackgroundGroupService backgroundGroupService;

    @Autowired
    private BackgroundUserService backgroundUserService;


    @Override
    public List<BackgroundComplainListVo> getComplainList(ComplainListVo complainListVo) {
        return backgroundComplainMapper.getComplainList(complainListVo);
    }

    @Override
    public int getComplainListCount(ComplainListVo complainListVo) {
        return backgroundComplainMapper.getComplainListCount(complainListVo);
    }

    @Override
    public void dealComplain(String id, int type) {
        ComplainPO complainPO = complainMapper.selectByPrimaryKey(id);
        if (StringHandler.isEmpty(complainPO)) {
            SystemError.wrapBs("500", "数据出错");
        }
        complainPO.setIsDeal(true);
        complainMapper.updateByPrimaryKeySelective(complainPO);
        if (type != 0) {
            if (type == 1) {
                //账号解封
                if (complainPO.getType() == 1) {
                    backgroundUserService.updateMiNingUserStatus(complainPO.getObjId(), 0);
                }
                if (complainPO.getType() == 2) {
                    backgroundGroupService.updateInfo(complainPO.getObjId(), 0);
                }
            }
            if (type == 2) {
                //封禁
                if (complainPO.getType() == 1) {
                    backgroundUserService.updateMiNingUserStatus(complainPO.getObjId(), 2);
                }
                if (complainPO.getType() == 2) {
                    backgroundGroupService.updateInfo(complainPO.getObjId(), 1);
                }
            }
        }
    }
}
